package com.lntea.redis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import redis.clients.jedis.Jedis;

public class HashDemo {
	Jedis jedis;
	
	@Before
	public void connect(){
		jedis = new Jedis("192.168.1.102", 6379);
	}
	
	@Test
	public void hset(){
		Long result = jedis.hset("hash", "field2", "2");
		System.out.println("hset result: "+result);
	}
	
	@Test
	public void hsetnx(){
		Long result = jedis.hsetnx("hash", "field5", "ttt");
		System.out.println("hsetnx result: "+result);
	}
	
	@Test
	public void hget(){
		String value = jedis.hget("hash", "field1");
		System.out.println("hget value: "+value);
	}
	
	@Test
	public void hexists(){
		Boolean isExists = jedis.hexists("hash", "field1");
		System.out.println("hexists: "+isExists);
	}
	
	@Test
	public void hdel(){
		Long result = jedis.hdel("hash", "field1");
		System.out.println("hdel result: "+result);
	}
	
	@Test
	public void hgetAll(){
		Map<String, String> map = jedis.hgetAll("hash");
		System.out.println(map.toString());
	}
	
	@Test
	public void hincrBy(){
		Long result = jedis.hincrBy("hash", "field2", 2);
		System.out.println("hincrBy result: "+result);
	}
	
	@Test
	public void hkeys(){
		Set<String> keys = jedis.hkeys("hash");
		System.out.println(keys.toString());
	}
	
	@Test
	public void hlen(){
		Long len = jedis.hlen("hash");
		System.out.println("hlen: "+len);
	}
	
	@Test
	public void hmget(){
		List<String> list = jedis.hmget("hash", "field1","field2");
		System.out.println(list.toString());
	}
	
	@Test
	public void hmset(){
		Map<String, String> hash = new HashMap<String, String>();
		hash.put("field3", "3");
		hash.put("field4", "abc");
		String result = jedis.hmset("hash", hash);
		System.out.println("hmset result: "+result);
	}
	
	@Test
	public void hvals(){
		List<String> list = jedis.hvals("hash");
		System.out.println(list.toString());
	}
	
}
